package com.caihao.docdemo;

import com.caihao.docdemo.util.AsposeWordsUtils;
import com.caihao.docdemo.util.WordUtil;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

/**
 * create by caihao on 2021/4/6
 */
public class Main {
    public static void main(String[] args) throws Exception {
        String path = Main.class.getClassLoader().getResource("file/test").getPath();
        Map<String,Object> dataMap = new HashMap<>();
        dataMap.put("title","个人介绍");
        dataMap.put("name","张三");
        dataMap.put("age",18);
        dataMap.put("address","shanghai");
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        // 替换word模板，此时word模板的内容在ByteArrayOutputStream流里面
        WordUtil.createDocx(path,dataMap,"test.docx",baos);
        // 将word对应的流内容转成pdf保存
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        FileOutputStream fos = new FileOutputStream(new File("D:/test.pdf"));
        AsposeWordsUtils.word2pdf(bais, fos);
    }
}
